//#ifndef decomp_js
//#define decomp_js 1

//#include "press.js"
//#include "instream.js"
//#include "decompdict.js"

// LZW decompression algorithm. See http://en.wikipedia.org/wiki/LZW
pressJs.decompress = function(encodedString) {
  var instream = new InStream(encodedString),
      dict = new DecompressDictionary(),
      numBits = dict.ValSizeInBits(),
      k = instream.Read(numBits),
      output = String.fromCharCode(k),
      w = output,
      entry = '';

  while ((k = instream.Read(numBits)) != null) {
    if (k < dict.Size()) { // is it in the dictionary?
      entry = dict.LookupIndex(k); // Get corresponding string.
    } else {
      entry = w + w.charAt(0);
    }
    output += entry;
    numBits = dict.Insert(w + entry.charAt(0));
    w = entry;
  }

  return output;
}

//#endif

